package moonlit.chill.pay.vo;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;

import java.util.HashMap;

/**
 * @author MoonlitChill
 * @date 2024/4/25 14:41
 */
public class RequestResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    /**
     * 状态码
     */
    public static final String CODE_TAG = "code";

    /**
     * 返回内容
     */
    public static final String MSG_TAG = "msg";

    /**
     * 数据对象
     */
    public static final String DATA_TAG = "data";

    /**
     * 错误状态码
     */
    public static final String ERROR_CODE = "errorCode";

    public RequestResult(int code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public RequestResult(int code, String msg, Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        if (ObjectUtil.isNotEmpty(data)) {
            super.put(DATA_TAG, data);
        }
    }

    public RequestResult(int code, String msg, Object data, Integer errorCode) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(ERROR_CODE, errorCode);
        if (ObjectUtil.isNotEmpty(data)) {
            super.put(DATA_TAG, data);
        }
    }

    public static RequestResult success() {
        return RequestResult.success("操作成功");
    }

    public static RequestResult success(Object data) {
        return RequestResult.success("操作成功", data);
    }

    public static RequestResult successStringData(String data) {
        return RequestResult.success("操作成功", data);
    }

    public static RequestResult NoteStringFail(String data) {
        if (StrUtil.isEmpty(data)) {
            return RequestResult.successStringData("短信发送成功");
        } else {
            return RequestResult.error("操作成功,发送失败手机号有：" + data);
        }
    }

    public static RequestResult success(String msg) {
        return RequestResult.success(msg, null);
    }

    public static RequestResult success(String msg, Object data) {
        return new RequestResult(HttpStatus.HTTP_OK, msg, data);
    }

    public static RequestResult error() {
        return RequestResult.error("操作失败");
    }

    public static RequestResult error(String msg) {
        return RequestResult.error(msg, null);
    }

    public static RequestResult error(String msg, Object data) {
        return new RequestResult(HttpStatus.HTTP_INTERNAL_ERROR, msg, data);
    }

    public static RequestResult error(int code, String msg) {
        return new RequestResult(code, msg, null);
    }

    public static RequestResult error(int code, String msg, Integer errorCode) {
        if (errorCode == null) {
            return new RequestResult(code, msg, null);
        }
        return new RequestResult(code, msg, null, errorCode);
    }

}
